﻿using Entitas;
using UnityEngine;

public class MoveSystem : IExecuteSystem
{
    private IGroup<GameEntity> group;

    public MoveSystem (Contexts contexts)
    {
        group = contexts.game.GetGroup (GameMatcher.AllOf (GameMatcher.VelComp,GameMatcher.PhysicsTag, GameMatcher.ViewComp));
    }

    public void Execute ()
    {
        var dt = Time.deltaTime;
        foreach (var entity in group.GetEntities ())
        {
            var velComp   = entity.velComp;
            var rigidbody = ((IPhysics) entity.viewComp.view).rb2;
            rigidbody.velocity = velComp.value * 5;
        }
    }
}